/*************************************************************************
 * @file: hedcontroller.h
 * @date: 01/04/2012
 * TOPOL v1_0 - (c)copyright 2012 TEC/UFF
 *************************************************************************
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 ************************************************************************/

#ifndef _HEDCONTROLLER
#define _HEDCONTROLLER

// includes
//----------
#include "hedmodel.h"
#include "geomchecker.h"
#include "undoredo.h"

// forward declarations
//----------------------


/*!
 * CLASS
 * HEDController
 * 
 * This class is responsible to manipulate the model data structure in an
 * lower level manner.
 * 
 * @author Andre Pereira (andremaues@id.uff.br)
 * @version 1.0.0
 * @see HEDModel
 * @see GeomChecker
 * @see UndoRedo
 */
class HEDController
{

public:

  ////////////////////////////////////////////////
  ///  Constructor and Destructor Declaration  ///
  ////////////////////////////////////////////////

  /**
   * @brief Constructs the object that controls the Half-edge Data Structure
   */
	HEDController();

  ////////////////////////////////////
  ///  PUBLIC Methods Declaration  ///
  ////////////////////////////////////

  /**
   * @brief Adds a point in the Topological Data Structure
   * @param _x is the first coordinate of the point
   * @param _y is the second coordinate of the point
   * @param _z is the third coordinate of the point
   * @param _tol is the tolerance used to perform attraction verifications
   */
	void doAddPoint( double _x, double _y, double _z, double _tol );

  /**
   * @brief Adds a curve (line) in the Topological Data Structure
   * @param _x1 is the first coordinate of the first point of the curve
   * @param _y1 is the second coordinate of the first point of the curve
   * @param _z1 is the third coordinate of the first point of the curve
   * @param _x2 is the first coordinate of the second point of the curve
   * @param _y2 is the second coordinate of the second point of the curve
   * @param _z2 is the third coordinate of the second point of the curve
   * @param _tol is the tolerance used to perform attraction verifications
  */
	void doAddCurve( double _x1, double _y1, double _z1,
                   double _x2, double _y2, double _z2, double _tol );

  /**
   * @brief Adds a triangle in the Topological Data Structure
   */
	void doAddTriangle( double _x1, double _y1, double _z1,
                      double _x2, double _y2, double _z2,
                      double _x3, double _y3, double _z3 );

  /**
   * @brief Selects the entity nearest to the point with coordinates (x,y,z)
   * @param _x is the first coordinate of the point
   * @param _y is the second coordinate of the point
   * @param _z is the third coordinate of the point
   * @param _tol is the tolerance used to perform attraction verifications
   */
  void doSelection( double _x, double _y, double _z, double _tol );

  /**
   * @brief Unselects the model entities
   */
  void doUnSelection();

  /**
   * @brief Performs an undo operation
   */
  void doUndo();

  /**
   * @brief Performs a redo operation
   */
  void doRedo();

  /**
   * @brief Gets a copy of the object that contains the model data
   * @return HEDModel is the copy of the model
   */
  HEDModel getModel();

  /**
   * @brief Verifies if it is possible to perform an undo operation
   * @return bool is the indication if undo is allowed
   */
  bool hasUndo();

  /**
   * @brief Verifies if it is possible to perform a redo operation
   * @return bool is the indication if redo is allowed
   */
  bool hasRedo();


private:

  ////////////////////////////////
  ///  Attributes Declaration  ///
  ////////////////////////////////

  /** @brief Manages the topological entities that belong to the Data Structure */
  HEDModel m_model;

  /** @brief Allows to perform geometric tests before make any decision */
  GeomChecker m_geomChecker;

  /** @brief Manages the undo and redo operations of commands carried out in the DS */
  UndoRedo m_undoredo;

};

#endif
